package com.superman.supermarket.client.view.refundprocess;

import java.util.List;
import java.util.Map;

import com.google.gwt.core.client.GWT;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;
import com.superman.mvpframe.client.mvp.IPageViewPresenter;
import com.superman.mvpframe.client.utils.XJsonUtil;
import com.superman.supermarket.client.composite.orderlist.opt.OrderListOpButton;
import com.superman.supermarket.client.composite.refundprocess.RefundProcessModule;

/**
 * 退款流程页面
 * 
 * @author superman
 * @version 2018年8月20日下午11:42:45
 */
public class RefundProcessViewImpl extends Composite implements RefundProcessView {

	interface RefundProcessViewImplUiBinder extends UiBinder<Widget, RefundProcessViewImpl> {
	}

	private static RefundProcessViewImplUiBinder uiBinder = GWT.create(RefundProcessViewImplUiBinder.class);

	@UiField
	FlowPanel listpanel, bottompanel;

	/**
	 * 构造方法
	 * 
	 * @author superman
	 * @version 2018年8月20日 下午11:42:42
	 */
	public RefundProcessViewImpl() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	@Override
	public void init() {
		// TODO Auto-generated method stub

	}

	@Override
	public void setPageViewPresenter(IPageViewPresenter presenter) {
		// TODO Auto-generated method stub

	}

	@Override
	public void setRefundProcess(Map<String, Object> map) {
		bottompanel.clear();
		// 可操作的按钮
		if (map.get("OP") == null || XJsonUtil.getOnlyList((JSONArray) map.get("OP")).size() == 0)
			bottompanel.removeFromParent();
		else {
			List<Object> ops = XJsonUtil.getOnlyList((JSONArray) map.get("OP"));
			for (Object object : ops) {
				int op = (int) Double.parseDouble(String.valueOf(object));
				OrderListOpButton orderListOpButton = new OrderListOpButton(map, op);
				bottompanel.add(orderListOpButton);
			}
		}

		List<Map<String, Object>> processList = XJsonUtil.getList((JSONArray) map.get("PROCESS"));
		listpanel.clear();
		for (Map<String, Object> processMap : processList) {
			RefundProcessModule refundProcessModule = new RefundProcessModule();
			refundProcessModule.setData(processMap);
			listpanel.add(refundProcessModule);
		}
	}

}
